package com.zp.qualitypractice.Mvp;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by izp on 2017/4/13.
 */

public  class RxPresenter<T extends MvpBase.BaseView> implements MvpBase.BasePresenter<T> {
    protected T mView;
    protected  CompositeDisposable mCompositeDisposable;
    @Override
    public void attachView(T view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        this.mView = null;
        unDisposable();
    }

    private void unDisposable() {
        if (mCompositeDisposable != null) {
            mCompositeDisposable.clear();
        }
    }

    void addDisposable(Disposable disposable) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeDisposable();
        }
        mCompositeDisposable.add(disposable);

    }
}
